﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
using Barbar.MapReport.GeoCoding;
using Barbar.MapReport.Configuration;
using Barbar.MapReport.Common;

[XmlTypeAttribute(TypeName = "Contacts")]
public class ContactCollection : Collection<Contact> {
  public void EnsureGps() {
    GeocoderService service = new GeocoderService();
    foreach (Contact contact in this) {
      GeocoderResponse response = service.GeocodeAddress(contact.Address, MapConfigurationManager.MapSettings.GoogleKeyProvider.DefaultGoogleKey);
      if (response.RequestOk && response.Points.Length == 1) {
        GeoPoint point = response.Points[0];
        contact.Latitude = point.Latitude;
        contact.Longitude = point.Longitude;
      }
    }
  }
}
